#include <iostream>
using namespace std;
typedef struct{
	int cost;
	int d;
	int w;
}inn;
int main(){
	int n,cost;
	cin>>n;
	inn a[n];
	for(int i = 0;i<n;++i){
		cin>>a[i].cost>>a[i].d>>a[i].w;
	}
	int attack,max = 0;
	bool guai;
	for(int i = 0;i<=(1<<n);++i){
		attack = cost = guai = 0;
		for(int j = 0;j<n;++j){
			if((i&(1<<j))&&cost+a[j].cost<=10){
				if(a[j].d==0)
					guai = true; 
				cost+=a[j].cost;
				attack+=a[j].w;
			}
		}
		if(guai&&attack>max)
			max = attack;
	}
	cout<<max;
	return 0;
}